
<html>
<title>event - Pygame Documentation</title>
<body bgcolor=#aaeebb text=#000000 link=#331111 vlink=#331111>


<table cellpadding=0 cellspacing=0 border=0 style='border: 3px solid black;' width='100%'>
<tr>
<td bgcolor='#c2fc20' style='padding: 6px;' align=center valign=center><a href='http://www.pygame.org/'><img src='../pygame_tiny.gif' border=0 width=200 height=60></a><br><b>pygame documentation</b></td>
<td bgcolor='#6aee28' style='border-left: 3px solid black; padding: 6px;' align=center valign=center>
	||&nbsp;
	<a href=http://www.pygame.org>Pygame Home</a> &nbsp;||&nbsp;
	<a href=../index.html>Help Contents</a> &nbsp;||
	<a href=index.html>Reference Index</a> &nbsp;||
	<br>&nbsp;<br>
	
<a href=cdrom.html>Cdrom</a>&nbsp;||&nbsp;
<a href=cursors.html>Cursors</a>&nbsp;||&nbsp;
<a href=display.html>Display</a>&nbsp;||&nbsp;
<a href=draw.html>Draw</a>&nbsp;||&nbsp;
<a href=event.html>Event</a>&nbsp;||&nbsp;
<a href=font.html>Font</a>&nbsp;||&nbsp;
<a href=image.html>Image</a>&nbsp;||&nbsp;
<a href=joystick.html>Joystick</a>&nbsp;||&nbsp;
<a href=key.html>Key</a>&nbsp;||&nbsp;
<a href=mixer.html>Mixer</a>&nbsp;||&nbsp;
<a href=mouse.html>Mouse</a>&nbsp;||&nbsp;
<a href=movie.html>Movie</a>&nbsp;||&nbsp;
<a href=music.html>Music</a>&nbsp;||&nbsp;
<a href=overlay.html>Overlay</a>&nbsp;||&nbsp;
<a href=pygame.html>Pygame</a>&nbsp;||&nbsp;
<a href=rect.html>Rect</a>&nbsp;||&nbsp;
<a href=scrap.html>Scrap</a>&nbsp;||&nbsp;
<a href=sndarray.html>Sndarray</a>&nbsp;||&nbsp;
<a href=sprite.html>Sprite</a>&nbsp;||&nbsp;
<a href=surface.html>Surface</a>&nbsp;||&nbsp;
<a href=surfarray.html>Surfarray</a>&nbsp;||&nbsp;
<a href=time.html>Time</a>&nbsp;||&nbsp;
<a href=transform.html>Transform</a>
</td></tr></table>
<br>


<a name="pygame.event">
<big><b>pygame.event</big></b><br><ul>
  <i>pygame module for interacting with events and queues</i><br>
<ul><small><table>
  <tr><td><a href="event.html#pygame.event.pump">pygame.event.pump</a> - <font size=-1>internally process pygame event handlers</font></td><td>internally process pygame event handlers</td></tr>
  <tr><td><a href="event.html#pygame.event.get">pygame.event.get</a> - <font size=-1>get events from the queue</font></td><td>get events from the queue</td></tr>
  <tr><td><a href="event.html#pygame.event.poll">pygame.event.poll</a> - <font size=-1>get a single event from the queue</font></td><td>get a single event from the queue</td></tr>
  <tr><td><a href="event.html#pygame.event.wait">pygame.event.wait</a> - <font size=-1>wait for a single event from the queue</font></td><td>wait for a single event from the queue</td></tr>
  <tr><td><a href="event.html#pygame.event.peek">pygame.event.peek</a> - <font size=-1>test if event types are waiting on the queue</font></td><td>test if event types are waiting on the queue</td></tr>
  <tr><td><a href="event.html#pygame.event.clear">pygame.event.clear</a> - <font size=-1>remove all events from the queue</font></td><td>remove all events from the queue</td></tr>
  <tr><td><a href="event.html#pygame.event.event_name">pygame.event.event_name</a> - <font size=-1>get the string name from and event id</font></td><td>get the string name from and event id</td></tr>
  <tr><td><a href="event.html#pygame.event.set_blocked">pygame.event.set_blocked</a> - <font size=-1>control which events are allowed on the queue</font></td><td>control which events are allowed on the queue</td></tr>
  <tr><td><a href="event.html#pygame.event.set_allowed">pygame.event.set_allowed</a> - <font size=-1>control which events are allowed on the queue</font></td><td>control which events are allowed on the queue</td></tr>
  <tr><td><a href="event.html#pygame.event.get_blocked">pygame.event.get_blocked</a> - <font size=-1>test if a type of event is blocked from the queue</font></td><td>test if a type of event is blocked from the queue</td></tr>
  <tr><td><a href="event.html#pygame.event.set_grab">pygame.event.set_grab</a> - <font size=-1>control the sharing of input devices with other applications</font></td><td>control the sharing of input devices with other applications</td></tr>
  <tr><td><a href="event.html#pygame.event.get_grab">pygame.event.get_grab</a> - <font size=-1>test if the program is sharing input devices</font></td><td>test if the program is sharing input devices</td></tr>
  <tr><td><a href="event.html#pygame.event.post">pygame.event.post</a> - <font size=-1>place a new event on the queue</font></td><td>place a new event on the queue</td></tr>
  <tr><td><a href="event.html#pygame.event.Event">pygame.event.Event</a> - <font size=-1>create a new event object</font></td><td>create a new event object</td></tr>
</table></small></ul>
<p>Pygame handles all it's event messaging through an event queue. The routines in this module help you manage that event queue. The input queue is heavily dependent on the pygame display module. If the display has not been initialized and a video mode not set, the event queue will not really work. </p>
<p>The queue is a regular queue of Event objects, there are a variety of ways to access the events it contains. From simply checking for the existance of events, to grabbing them directly off the stack. </p>
<p>All events have a type identifier. This event type is in between the values of <tt>NOEVENT</tt> and <tt>NUMEVENTS</tt>. All user defined events can have the value of <tt>USEREVENT</tt> or higher. It is recommended make sure your event id's follow this system. </p>
<p>To get the state of various input devices, you can forego the event queue and access the input devices directly with their appropriate modules; mouse, key, and joystick. If you use this method, remember that pygame requires some form of communication with the system window manager and other parts of the platform. To keep pygame in synch with the system, you will need to call <tt><a href="event.html#pygame.event.pump">pygame.event.pump</a> - <font size=-1>internally process pygame event handlers</font></tt> to keep everything current. You'll want to call this function usually once per game loop. </p>
<p>The event queue offers some simple filtering. This can help performance slightly by blocking certain event types from the queue, use the <tt><a href="event.html#pygame.event.set_allowed">pygame.event.set_allowed</a> - <font size=-1>control which events are allowed on the queue</font></tt> and <tt><a href="event.html#pygame.event.set_blocked">pygame.event.set_blocked</a> - <font size=-1>control which events are allowed on the queue</font></tt> to work with this filtering. All events default to allowed. </p>
<p>Joysticks will not send any events until the device has been initialized. </p>
<p>An Event object contains an event type and a readonly set of member data. The Event object contains no method functions, just member data. Event objects are retrieved from the pygame event queue. You can create your own new events with the <tt><a href="event.html#pygame.event.Event">pygame.event.Event</a> - <font size=-1>create a new event object</font></tt> function. </p>
<p>Your program must take steps to keep the event queue from overflowing. If the program is not clearing or getting all events off the queue at regular intervals, it can overflow. When the queue overflows an exception is thrown. </p>
<p>All Event objects contain an event type identifier in the <tt>Event.type</tt> member. You may also get full access to the Event's member data through the <tt>Event.dict</tt> method. All other member lookups will be passed through to the Event's dictionary values. </p>
<p>While debugging and experimenting, you can print the Event objects for a quick display of its type and members. Events that come from the system will have a guaranteed set of member items based on the type. Here is a list of the Event members that are defined with each type. </p>
<pre>    QUIT	     none
    ACTIVEEVENT	     gain, state
    KEYDOWN	     unicode, key, mod
    KEYUP	     key, mod
    MOUSEMOTION	     pos, rel, buttons
    MOUSEBUTTONUP    pos, button
    MOUSEBUTTONDOWN  pos, button
    JOYAXISMOTION    joy, axis, value
    JOYBALLMOTION    joy, ball, rel
    JOYHATMOTION     joy, hat, value
    JOYBUTTONUP      joy, button
    JOYBUTTONDOWN    joy, button
    VIDEORESIZE      size, w, h
    VIDEOEXPOSE      none
    USEREVENT        code
</pre>
<!--COMMENTS:pygame.event--> &nbsp;<br> 


<a name="pygame.event.pump">
<big><b>pygame.event.pump</big></b><br><ul>
  <i>internally process pygame event handlers</i><br>
  <tt>pygame.event.pump(): return None</tt><br>
<p>For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system. If you are not using other event functions in your game, you should call <tt><a href="event.html#pygame.event.pump">pygame.event.pump</a> - <font size=-1>internally process pygame event handlers</font></tt> to allow pygame to handle internal actions. </p>
<p>This function is not necessary if your program is consistently processing events on the queue through the other <tt>pygame.event</tt> functions. </p>
<p>There are important things that must be dealt with internally in the event queue. The main window may need to be repainted or respond to the system. If you fail to make a call to the event queue for too long, the system may decide your program has locked up. </p>
<!--COMMENTS:pygame.event.pump--> &nbsp;<br> 
<br></ul>


<a name="pygame.event.get">
<big><b>pygame.event.get</big></b><br><ul>
  <i>get events from the queue</i><br>
  <tt>pygame.event.get(): return Eventlist</tt><br>
  <tt>pygame.event.get(type): return Eventlist</tt><br>
  <tt>pygame.event.get(typelist): return Eventlist</tt><br>
<p>This will get all the messages and remove them from the queue. If a type or sequence of types is given only those messages will be removed from the queue. </p>
<p>If you are only taking specific events from the queue, be aware that the queue could eventually fill up with the events you are not interested. </p>
<!--COMMENTS:pygame.event.get--> &nbsp;<br> 
<br></ul>


<a name="pygame.event.poll">
<big><b>pygame.event.poll</big></b><br><ul>
  <i>get a single event from the queue</i><br>
  <tt>pygame.event.poll(): return Event</tt><br>
<p>Returns a single event from the queue. If the event queue is empty an event of type <tt>pygame.NOEVENT</tt> will be returned immediately. The returned event is removed from the queue. </p>
<!--COMMENTS:pygame.event.poll--> &nbsp;<br> 
<br></ul>


<a name="pygame.event.wait">
<big><b>pygame.event.wait</big></b><br><ul>
  <i>wait for a single event from the queue</i><br>
  <tt>pygame.event.wait(): return Event</tt><br>
<p>Returns a single event from the queue. If the queue is empty this function will wait until one is created. While the program is waiting it will sleep in an idle state. This is important for programs that want to share the system with other applications. </p>
<!--COMMENTS:pygame.event.wait--> &nbsp;<br> 
<br></ul>


<a name="pygame.event.peek">
<big><b>pygame.event.peek</big></b><br><ul>
  <i>test if event types are waiting on the queue</i><br>
  <tt>pygame.event.peek(type): return bool</tt><br>
  <tt>pygame.event.peek(typelist): return bool</tt><br>
<p>Returns true if there are any events of the given type waiting on the queue. If a sequence of event types is passed, this will return True if any of those events are on the queue. </p>
<!--COMMENTS:pygame.event.peek--> &nbsp;<br> 
<br></ul>


<a name="pygame.event.clear">
<big><b>pygame.event.clear</big></b><br><ul>
  <i>remove all events from the queue</i><br>
  <tt>pygame.event.clear(): return None</tt><br>
  <tt>pygame.event.clear(type): return None</tt><br>
  <tt>pygame.event.clear(typelist): return None</tt><br>
<p>Remove all events or events of a specific type from the queue. This has the same effect as <tt><a href="event.html#pygame.event.get">pygame.event.get</a> - <font size=-1>get events from the queue</font></tt> except nothing is returned. This can be slightly more effecient when clearing a full event queue. </p>
<!--COMMENTS:pygame.event.clear--> &nbsp;<br> 
<br></ul>


<a name="pygame.event.event_name">
<big><b>pygame.event.event_name</big></b><br><ul>
  <i>get the string name from and event id</i><br>
  <tt>pygame.event.event_name(type): return string</tt><br>
<p>Pygame uses integer ids to represent the event types. If you want to report these types to the user they should be converted to strings. This will return a the simple name for an event type. The string is in the WordCap style. </p>
<!--COMMENTS:pygame.event.event_name--> &nbsp;<br> 
<br></ul>


<a name="pygame.event.set_blocked">
<big><b>pygame.event.set_blocked</big></b><br><ul>
  <i>control which events are allowed on the queue</i><br>
  <tt>pygame.event.set_blocked(type): return None</tt><br>
  <tt>pygame.event.set_blocked(typelist): return None</tt><br>
  <tt>pygame.event.set_blocked(None): return None</tt><br>
<p>The given event types are not allowed to appear on the event queue. By default all events can be placed on the queue. It is safe to disable an event type multiple times. </p>
<p>If None is passed as the argument, this has the opposite effect and none of the event types are allowed to be placed on the queue. </p>
<!--COMMENTS:pygame.event.set_blocked--> &nbsp;<br> 
<br></ul>


<a name="pygame.event.set_allowed">
<big><b>pygame.event.set_allowed</big></b><br><ul>
  <i>control which events are allowed on the queue</i><br>
  <tt>pygame.event.set_allowed(type): return None</tt><br>
  <tt>pygame.event.set_allowed(typelist): return None</tt><br>
  <tt>pygame.event.set_allowed(None): return None</tt><br>
<p>The given event types are allowed to appear on the event queue. By default all events can be placed on the queue. It is safe to enable an event type multiple times. </p>
<p>If None is passed as the argument, this has the opposite effect and all of the event types are allowed to be placed on the queue. </p>
<!--COMMENTS:pygame.event.set_allowed--> &nbsp;<br> 
<br></ul>


<a name="pygame.event.get_blocked">
<big><b>pygame.event.get_blocked</big></b><br><ul>
  <i>test if a type of event is blocked from the queue</i><br>
  <tt>pygame.event.get_blocked(type): return bool</tt><br>
<p>Returns true if the given event type is blocked from the queue. </p>
<!--COMMENTS:pygame.event.get_blocked--> &nbsp;<br> 
<br></ul>


<a name="pygame.event.set_grab">
<big><b>pygame.event.set_grab</big></b><br><ul>
  <i>control the sharing of input devices with other applications</i><br>
  <tt>pygame.event.set_grab(bool): return None</tt><br>
<p>When your program runs in a windowed environment, it will share the mouse and keyboard devices with other applications that have focus. If your program sets the event grab to True, it will lock all input into your program. </p>
<p>It is best to not always grab the input, since it prevents the user from doing other things on their system. </p>
<!--COMMENTS:pygame.event.set_grab--> &nbsp;<br> 
<br></ul>


<a name="pygame.event.get_grab">
<big><b>pygame.event.get_grab</big></b><br><ul>
  <i>test if the program is sharing input devices</i><br>
  <tt>pygame.event.get_grab(): return bool</tt><br>
<p>Returns true when the input events are grabbed for this application. Use <tt><a href="event.html#pygame.event.set_grab">pygame.event.set_grab</a> - <font size=-1>control the sharing of input devices with other applications</font></tt> to control this state. </p>
<!--COMMENTS:pygame.event.get_grab--> &nbsp;<br> 
<br></ul>


<a name="pygame.event.post">
<big><b>pygame.event.post</big></b><br><ul>
  <i>place a new event on the queue</i><br>
  <tt>pygame.event.post(Event): return None</tt><br>
<p>This places a new event at the end of the event queue. These Events will later be retrieved from the other queue functions. </p>
<p>This is usually used for placing <tt>pygame.USEREVENT</tt> events on the queue. Although any type of event can be placed, if using the sytem event types your program should be sure to create the standard attributes with appropriate values. </p>
<!--COMMENTS:pygame.event.post--> &nbsp;<br> 
<br></ul>


<a name="pygame.event.Event">
<big><b>pygame.event.Event</big></b><br><ul>
  <i>create a new event object</i><br>
  <tt>pygame.event.Event(type, dict): return Event</tt><br>
  <tt>pygame.event.Event(type, **attributes): return Event</tt><br>
<p>Creates a new event with the given type. The event is created with the given attributes and values. The attributes can come from a dictionary argument, or as string keys from a dictionary. </p>
<p>The given attributes will be readonly attributes on the new event object itself. These are the only attributes on the Event object, there are no methods attached to Event objects. </p>
<!--COMMENTS:pygame.event.Event--> &nbsp;<br> 
<br></ul>
<br></ul>

</body></html>
